package com.otv.core;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.otv.model.Role;
import com.otv.model.User;

@TransactionManagement(TransactionManagementType.CONTAINER)
@Stateless
public class PmDelegate {
	@PersistenceContext(unitName = "StoreForceAdministration")
	EntityManager entityManager;

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public void persist(Object object) {
		entityManager.persist(object);
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public void mergeAndPersist(Object object) {
		Object merged = entityManager.merge(object);
		entityManager.persist(merged);
		System.out.println("saving " + object.getClass() + " with success");
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public Object merge(Object object) {
		Object merged = entityManager.merge(object);
		return merged;
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public void remove(Object object) {
		// Object merge = entityManager.merge(object);
		entityManager.remove(object);
		System.out.println("end");
	}
	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public void mergeAndRemove(String object) {
		String merged = entityManager.merge(object);
		entityManager.remove(merged);
		System.out.println("end");
		
	}

}
